minfo.c: open device rw due to possible ioctl call #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This gets floppy auto configuration to work (again), i.e.:
mtools should set up the drive according to the geometry it finds when
accessing the boot sector (number of sectors, cylinders, ect). This
worked fine on my (old) machine, using the stock kernel for Debian 4.0
(yes, that old). Because it was so old, I decided to install Debian 8.0
(the last that supports the CPU). Now, mtools does not work anymore, at
least not without specifying the exact format of the disk before using
it. This is especially a problem because I do have 5.25 inch floppies
which are a mix between the (usual) 1.2MB and 1.44MB-formatted kind (and
several smaller ones). Guessing the correct format each time isn't
exactly fun, especially when you know that mtools should have the
necessary logic already built-in.
On the surface, where before
mdir b:
gave me a directory listing, using the same disk, I now get:
Can't set disk parameters for B: Operation not permitted
Cannot initialize 'B:'
This is, however, not a regression in mtools itself: the old binary is
still executable within the new Linux installation, but shows the same
problem, regardless of mtools version 3.9.10 or 4.0.18.
After reading the source of mtools and the kernel source of the floppy
driver and especially fs/block_dev.c, I see that ioctl-access is only
granted if mode & O_ACCMODE == 3. "3" is O_RDWR.
The device is opened in minfo.c within find_device(), but the mode is
one of its arguments. One usage of this is within minfo.c, but there
O_RDONLY is given as mode. Changing this to O_RDWR makes minfo work
again: the ioctl call succeeds because the FD was opened with write
permissions.
This also makes sense, as opening the device using O_RDONLY
should not allow for (those) ioctls to be sent. However, even if mtools
only plans to read from the drive, it needs to send those ioctls to
configure the drive correctly, and thus needs to open the device using
O_RDWR - which is the only thing this patch changes.